//
//  HomeManager1.m
//  wsgz
//
//  Created by huck on 2017/5/7.
//  Copyright © 2017年 BoingPay. All rights reserved.
//

#import "HomeManager.h"
#import "AppUtils.h"
#import "HttpRequest.h"
#import "HttpRequest1.h"


#define kRequestPageSize 10

@implementation BannerViewData
- (instancetype)init
{
    if (self = [super init]) {
    }
    return self;
}

- (void)setInfo:(NSDictionary *)dic
{
    _title = [AppUtils toString:dic[@"name"]];
    _image = [AppUtils toString:dic[@"image"]];
    _linkUrl = [AppUtils toString:dic[@"link_url"]];
}

@end

@implementation WaterInfoData
- (instancetype)init
{
    if (self = [super init]) {
    }
    return self;
}
- (void)setInfo:(NSDictionary *)dic
{
    _waterId = [AppUtils toString:dic[@"watId"]];
    _taskId = [AppUtils toString:dic[@"id"]];
    _waterName = [AppUtils toString:dic[@"wName"]];
    _waterLevelName = [AppUtils toString:dic[@"wLevelName"]];
    _waterQualityClassName = [AppUtils toString:dic[@"wQualityClassName"]];
    _dutyArea = [AppUtils toString:dic[@"dutyArea"]];
    _waterLocation = [AppUtils toString:dic[@"wLocation"]];
    _isDirect =[@"Y" isEqualToString:[AppUtils toString:dic[@"isDirect"]]];
    if([dic.allKeys containsObject:@"type"]){
        _taskStatus = [AppUtils toInteger:dic[@"type"]];
    }else{
        _taskStatus = TaskStatusTypeNone;
    }
    _scoutTime = [AppUtils toString:dic[@"scoutTime"]];
}

@end

@implementation WaterInfoDetailData
- (instancetype)init
{
    if (self = [super init]) {
        _positionList = [NSMutableArray array];
        _badReasonAnalysis = [NSMutableArray array];
        _badManageScheme = [NSMutableArray array];
    }
    return self;
}

- (void)setInfo:(NSDictionary *)dic
{
    _waterId = [AppUtils toString:dic[@"id"]];
    _waterName = [AppUtils toString:dic[@"wName"]];
    _waterLevelName = [AppUtils toString:dic[@"wLvelName"]];
    _waterlength = [AppUtils toString:dic[@"wLength"]];
    _waterQualityClassName = [AppUtils toString:dic[@"wTypeName"]];
    _dutyArea = [AppUtils toString:dic[@"dutyArea"]];
    _waterStart = [AppUtils toString:dic[@"wStart"]];
    _waterEnd = [AppUtils toString:dic[@"wEnd"]];
    _manager = [AppUtils toString:dic[@"manager"]];
    _superviseName = [AppUtils toString:dic[@"superviseName"]];
    _dutyName = [AppUtils toString:dic[@"dutyName"]];
    _waterLabel = [AppUtils toString:dic[@"wLabel"]];
    _mapLevel = [AppUtils toInteger:dic[@"mapLevel"]];
    if(_mapLevel<3||_mapLevel>21){
        _mapLevel = DEFAULT_MAP_LEVEL;
    }
    _mapTag = [AppUtils toString:dic[@"mapTag"]];
    _isDirect =[@"Y" isEqualToString:[AppUtils toString:dic[@"isDirect"]]];
    NSArray *arr = dic[@"positions"];
    for(NSDictionary *dict in arr){
        PositionInfoData *data = [[PositionInfoData alloc] init];
        [data setInfo:dict];
        [_positionList addObject:data];
    }

    _waterLocation = [AppUtils toString:dic[@"wLocation"]];
    _showYDYC = [@"1" isEqualToString:[AppUtils toString:dic[@"directStatus"]]];
    
    NSArray *arr1 = dic[@"directReasonAnalysis"];
    for(NSDictionary *dict in arr1){
        BadReasonItemData *item  = [[BadReasonItemData alloc] init];
        [item setInfo:dict labelKey:@"reasonAnalysis"];
        [_badReasonAnalysis addObject:item];
    }
    NSArray *arr2 = dic[@"directManageScheme"];
    for(NSDictionary *dict in arr2){
        BadReasonItemData *item  = [[BadReasonItemData alloc] init];
        [item setInfo:dict labelKey:@"manageScheme"];
        [_badManageScheme addObject:item];
    }
}

@end

@implementation PositionInfoData
- (void)setInfo:(NSDictionary *)dic
{
    _position = [AppUtils toString:dic[@"position"]];
    _isDirect =[@"Y" isEqualToString:[AppUtils toString:dic[@"isDirect"]]];
    _dirtyName = [AppUtils toString:dic[@"dirtyName"]];
    _dirtyPlace = [AppUtils toString:dic[@"dirtyPlace"]];
    _dirtyType = [AppUtils toString:dic[@"dirtyType"]];
    _status = [AppUtils toString:dic[@"status"]];
}
@end

//tab页水体名称搜索列表的数据
@implementation WaterDirtyData

- (void)setInfo:(NSDictionary *)dic
{
    _dirtyId = [AppUtils toString:dic[@"id"]];
    _waterId = [AppUtils toString:dic[@"waterId"]];
    _waterName = [AppUtils toString:dic[@"wName"]];
    _mapLevel = [AppUtils toInteger:dic[@"mapLevel"]];
    if(_mapLevel<3||_mapLevel>21){
        _mapLevel = DEFAULT_MAP_LEVEL;
    }
    _mapTag = [AppUtils toString:dic[@"mapTag"]];
    _waterLocation = [AppUtils toString:dic[@"wLocation"]];
    _wTypeName = [AppUtils toString:dic[@"wTypeName"]];
    _position = [[PositionInfoData alloc] init];
    [_position setInfo:dic];
}

@end


@implementation BadReasonItemData
- (void)setInfo:(NSDictionary *)dic labelKey:(NSString *)key
{
    _value = [AppUtils toString:dic[key]];
    _detail = [AppUtils toString:dic[@"content"]];
}
@end

////排污口信息
//@implementation OutWaterItemData
//- (void)setInfo:(NSDictionary *)dic
//{
//    _name = [AppUtils toString:dic[@"name"]];
//    _type = [AppUtils toString:dic[@"type"]];
//    _isDirect =[@"Y" isEqualToString:[AppUtils toString:dic[@"isDirect"]]];
//    _location = [AppUtils toString:dic[@"location"]];
//}
//@end

//水体巡查列表
@implementation WaterRecodeItemData
- (instancetype)init
{
    if (self = [super init]) {
        _badReasonAnalysis = [NSMutableArray array];
        _badManageScheme = [NSMutableArray array];
        _manageFinishUrls = [NSMutableArray array];
        _inspectingUrls = [NSMutableArray array];
    }
    return self;
}
- (void)setInfo:(NSDictionary *)dic
{
    _recordId = [AppUtils toString:dic[@"id"]];
    _waterName = [AppUtils toString:dic[@"wName"]];
    _superviseName = [AppUtils toString:dic[@"superviseName"]];
    _supervisePropose = [AppUtils toString:dic[@"supervisePropose"]];
    _scoutName = [AppUtils toString:dic[@"scoutName"]];
    _scoutTime = [AppUtils toString:dic[@"scoutTime"]];
    _managerName = [AppUtils toString:dic[@"managerName"]];
    _scoutStatus = [AppUtils toInteger:dic[@"scoutStatus"]];
    _inspectPic = [AppUtils toString:dic[@"inspectPic"]];
    [_manageFinishUrls addObjectsFromArray:dic[@"manageFinishUrls"]];
    [_inspectingUrls addObjectsFromArray:dic[@"inspectingUrls"]];
    _resultType = [AppUtils toInteger:dic[@"resultStatus"]];
    _manageOpinion = [AppUtils toString:dic[@"manageOpinion"]];
    
    NSArray *arr1 = dic[@"directReasonAnalysis"];
    for(NSDictionary *dict in arr1){
        BadReasonItemData *item  = [[BadReasonItemData alloc] init];
        [item setInfo:dict labelKey:@"reasonAnalysis"];
        [_badReasonAnalysis addObject:item];
    }
    NSArray *arr2 = dic[@"directManageScheme"];
    for(NSDictionary *dict in arr2){
        BadReasonItemData *item  = [[BadReasonItemData alloc] init];
        [item setInfo:dict labelKey:@"manageScheme"];
        [_badManageScheme addObject:item];
    }
    _showYDYC = [@"1" isEqualToString:[AppUtils toString:dic[@"directStatus"]]];
}

-(NSString *)getScoutStatusStr
{   //巡查状态 0,1,2等待整改 整改中 整改完成
    return [AppUtils getScoutStatusStr:_scoutStatus];
}

@end

@implementation ProjectInfoData
- (instancetype)init
{
    if (self = [super init]) {
        _processList = [NSMutableArray array];
        _projectFileList = [NSMutableArray array];
    }
    return self;
}

- (void)setInfo:(NSDictionary *)dic
{
    _projectId = [AppUtils toString:dic[@"id"]];
    _projectName = [AppUtils toString:dic[@"projectName"]];
    _projectTypeName = [AppUtils toString:dic[@"projectTypeName"]];
    _planInvest = [AppUtils toString:dic[@"planInvest"]];
    _startTime = [AppUtils toString:dic[@"startDate"]];
    _finishTime = [AppUtils toString:dic[@"endDate"]];
    _leader = [AppUtils toString:dic[@"liable"]];
    _topLeader = [AppUtils toString:dic[@"lead"]];
    _tempo = [AppUtils toString:dic[@"tempo"]];
    _renovateName = [AppUtils toString:dic[@"renovateName"]];
    _dutyArea  = [AppUtils toString:dic[@"dutyArea"]];
    
    NSArray *arr = dic[@"ProjectRate"];
    for(NSDictionary *dict in arr){
        ProjectProcessData *data = [[ProjectProcessData alloc] init];
        [data setInfo:dict];
        [_processList addObject: data];
    }
    
    NSArray *arr1 = dic[@"files"];
    for(NSDictionary *dict in arr1){
        ProjectFileData *data = [[ProjectFileData alloc] init];
        [data setInfo:dict];
        [_projectFileList addObject: data];
    }
    _projectFileList =[NSMutableArray arrayWithArray:[AppUtils sortArray:_projectFileList descriptor:@"typeIndex" ascending:YES]];
}

@end

//项目进度
@implementation ProjectProcessData

- (instancetype)init
{
    if (self = [super init]) {
    }
    return self;
}

- (void)setInfo:(NSDictionary *)dic
{
    _processId = [AppUtils toString:dic[@"id"]];
    _percent = [AppUtils toString:dic[@"schedule"]].integerValue;
    _detail = [AppUtils toString:dic[@"procectDetail"]];
    _finishTime = [AppUtils toString:dic[@"proDate"]];
}

@end

//文件信息
@implementation ProjectFileData

- (void)setInfo:(NSDictionary *)dic
{
    _fileName = [AppUtils toString:dic[@"fileName"]];
    _realpath= [AppUtils toString:dic[@"realpath"]];
    _exeName = [_realpath pathExtension];
    _typeIndex = [AppUtils getFileTypeIndex:_exeName];
}
-(BOOL) isPicture
{
    return [@"png"isEqualToString:_exeName] || [@"jpg"isEqualToString:_exeName] || [@"jpeg"isEqualToString:_exeName] || [@"bmp"isEqualToString:_exeName];
}

- (NSString *)getIconName
{
    if([@"txt"isEqualToString:_exeName]) {
        return @"txt_icon";
    }
    else if([@"pdf"isEqualToString:_exeName] ){
        return @"pdf_icon";
    } else if([@"doc"isEqualToString:_exeName] || [@"docx"isEqualToString:_exeName] ){
       return @"word_icon";
    }else if([@"xls"isEqualToString:_exeName] || [@"xlsx"isEqualToString:_exeName] ){
        return @"execl_icon";
    }else if([@"ppt"isEqualToString:_exeName] || [@"pptx"isEqualToString:_exeName] ){
        return @"ppt_icon";
    }else{
        return _realpath;
    }
}


@end

//系统信息数据模型
@implementation SystemInfoData

- (void)setInfo:(NSDictionary *)dict
{
    _systemId = [AppUtils toString:dict[@"id"]];
    _systemValue = [AppUtils toString:dict[@"value"]];
    _systemLabel = [AppUtils toString:dict[@"label"]];

}

@end

//区域数据模型
@implementation RegionInfoData

-(instancetype)init
{
    self = [super init];
    if(self){
        self.subRegionList = [NSMutableArray array];
    }
    return self;
}
- (void)setInfo:(NSDictionary *)dict
{
    _regionId = [AppUtils toString:dict[@"value"]];
    _regionName = [AppUtils toString:dict[@"label"]];
    NSArray *sub = dict[@"rustic"];
    for(NSDictionary *dict in sub){
        RegionInfoData *data = [[RegionInfoData alloc] init];
        [data setInfo:dict];
        [self.subRegionList addObject:data];
    }
}
@end


@interface HomeManager()
@end

@implementation HomeManager

+ (instancetype)sharedInstance
{
    static HomeManager *instance;
    static dispatch_once_t pred;
    dispatch_once(&pred, ^{
        instance = [[HomeManager alloc] init];
        [instance initData];
    });
    return instance;
}

- (void)initData
{
    _bannerViewList = [[NSMutableArray alloc] init];
    _waterInfoList = [[NSMutableArray alloc] init];
    _projectInfoList = [[NSMutableArray alloc] init];
    
    _waterClassList = [[NSMutableArray alloc] init];
    _maschemeList = [[NSMutableArray alloc] init];
    _waterQualiList = [[NSMutableArray alloc] init];
    _reanalysisList = [[NSMutableArray alloc] init];
    _proManageList = [[NSMutableArray alloc] init];
    _proSortList = [[NSMutableArray alloc] init];
    
    _regionList = [NSMutableArray array];
    _undoneTaskList = [[NSMutableArray alloc] init];
    _doneTaskList = [[NSMutableArray alloc] init];
    _waterRecordList = [[NSMutableArray alloc] init];
    _waterDirtyList = [[NSMutableArray alloc] init];
    _waterMapList = [[NSMutableArray alloc] init];
    //多余
    [self setTempData];
}

//临时设置数据
-(void)setTempData
{
    NSArray *bannerArr = @[
                           @{@"name":@"广告1",@"image":@"banner_image1",@"link_url":@"http://www.baidu.com"},
                           @{@"name":@"广告2",@"image":@"banner_image2",@"link_url":@"http://www.baidu.com"},
                           @{@"name":@"广告3",@"image":@"banner_image3",@"link_url":@"http://www.baidu.com"},
                           @{@"name":@"广告4",@"image":@"banner_image4",@"link_url":@"http://www.baidu.com"},
                           @{@"name":@"广告5",@"image":@"banner_image5",@"link_url":@"http://www.baidu.com"}
                           ];
    for (NSDictionary *dict in bannerArr) {
        BannerViewData *data = [[BannerViewData alloc] init];
        [data setInfo:dict];
        [_bannerViewList addObject:data];
    }
}

//原因分析:农村生活污水污染""工业企业废水污染""生活垃圾或建筑垃圾等" 获取具体标签
-(NSString *)getReanalysisLabel:(NSString *)value
{
    NSString *result= nil;
    for(SystemInfoData *data in _reanalysisList){
        if([data.systemValue isEqualToString:value]){
            result = data.systemLabel;
            break;
        }
    }
    return result;
}

//整改方案:"截污纳管工程""清淤保洁工程""排口整改工程""生态引水与修复工程""科技治水工程" 获取具体标签
-(NSString *)getMaschemeLabel:(NSString *)value
{
    NSString *result= nil;
    for(SystemInfoData *data in _maschemeList){
        if([data.systemValue isEqualToString:value]){
            result = data.systemLabel;
            break;
        }
    }
    return result;
}

- (void)requestAppSystemInfo:(NSString *)code complete:(void (^)(BOOL success))complete
{
    if([AppUtils isEmpty:code]){
        complete(NO);
        return;
    }
    NSArray *codes = @[SYS_INFO_waterClass,SYS_INFO_waterQuali,SYS_INFO_reanalysis,SYS_INFO_mascheme,SYS_INFO_proSort,SYS_INFO_proManage];
    NSArray *lists = @[_waterClassList,_waterQualiList,_reanalysisList,_maschemeList,_proSortList,_proManageList];
    NSInteger index = [codes indexOfObject:code];
    NSMutableArray *addArr = lists[index];
    
    NSString *url = @"/app_system";
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:code forKey:@"code"];
    [[HttpRequest sharedHttpRequest] get:url params:params complete:^(BOOL success, NSDictionary *result) {
        
        [addArr removeAllObjects];
        if (success) {
            NSArray *resultList = result[@"data"];
            if([SYS_INFO_proSort isEqualToString:code]){
                SystemInfoData *infoData = [[SystemInfoData alloc] init];
                infoData.systemValue = @"";
                infoData.systemLabel = @"全部";
                [_proSortList addObject:infoData];
            }
            
            for (NSDictionary *dict in resultList) {
                SystemInfoData *infoData = [[SystemInfoData alloc] init];
                [infoData setInfo:dict];
                [addArr addObject:infoData];
            }
            complete(YES);
        }
        else {
            complete(NO);
            [AppUtils showErrorAlert: result[@"message"]];
        }
    }];
}

- (void)requestRegionInfo:(void (^)(BOOL success))complete
{
    NSString *url = @"/app_region";
    [[HttpRequest sharedHttpRequest] get:url params:nil complete:^(BOOL success, NSDictionary *result) {
        [_regionList removeAllObjects];
        
        if (success) {
            NSArray *resultList = result[@"data"];
           
            for (NSDictionary *dict in resultList) {
                RegionInfoData *infoData = [[RegionInfoData alloc] init];
                [infoData setInfo:dict];
                [_regionList addObject:infoData];
            }
            complete(YES);
        }
        else {
            complete(NO);
            [AppUtils showErrorAlert: result[@"message"]];
        }
    }];
}

- (void)requestSearchWater:(NSString *)wName wLevelId:(NSString *)wLevelId regionId:(NSString *)regionId wquestion:(NSString *)wquestion page:(NSInteger)pageNo reset:(BOOL)reset complete:(void (^)(BOOL success,BOOL hasMore))complete
{
    NSInteger pageSize = kRequestPageSize;
    NSString *url = @"/app_water";
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:wName forKey:@"wName"];
    [params setValue:regionId forKey:@"dutyArea"];
    [params setValue:wLevelId forKey:@"wLevelId"];
    [params setValue:wquestion forKey:@"wquestion"];
    [params setValue:[AppUtils toStr:pageNo] forKey:@"pageNo"];
    [params setValue:[AppUtils toStr:pageSize] forKey:@"pageSize"];
    
    [[HttpRequest sharedHttpRequest] get:url params:params complete:^(BOOL success, NSDictionary *result) {
        if (success) {
            if(reset){
                [_waterInfoList removeAllObjects];
            }
            NSDictionary *value = result[@"data"];

            NSArray *list= value[@"pageData"];
            for(NSDictionary *dict in list){
                WaterInfoData *infoData = [[WaterInfoData alloc] init];
                [infoData setInfo:dict];
                [_waterInfoList addObject:infoData];
            }
            BOOL more = list.count>=pageSize;
            complete(YES,more);
        }
        else {
            complete(NO,NO);
            [AppUtils showErrorAlert: result[@"message"]];
        }
    }];
}

-(void)requestWaterDetail:(NSString *)waterId complete:(void (^)(BOOL success))complete
{
    if([AppUtils isEmpty:waterId]){
        complete(NO);
        return;
    }
    NSString *url = [NSString stringWithFormat:@"/app_water/%@",waterId];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:waterId forKey:@"id"];
    
    [[HttpRequest sharedHttpRequest] get:url params:params complete:^(BOOL success, NSDictionary *result) {
        if (success) {
            NSDictionary *value = result[@"data"];
            _waterDetailInfo = [[WaterInfoDetailData alloc] init];
            [_waterDetailInfo setInfo:value];
            complete(YES);
        }
        else {
            complete(NO);
            [AppUtils showErrorAlert: result[@"message"]];
        }
    }];
}


- (void)requestSearchProject:(NSString *)projectName typeId:(NSString *)projectTypeId page:(NSInteger)pageNo reset:(BOOL)reset complete:(void (^)(BOOL success,BOOL hasMore))complete
{
    NSInteger pageSize = 15;

    NSString *url = @"/app_project";
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:projectName forKey:@"projectName"];
    [params setValue:projectTypeId forKey:@"projectTypeId"];
    [params setValue:[AppUtils toStr:pageNo] forKey:@"pageNo"];
    [params setValue:[AppUtils toStr:pageSize] forKey:@"pageSize"];
    
    [[HttpRequest sharedHttpRequest] get:url params:params complete:^(BOOL success, NSDictionary *result) {
        if (success) {
            if(reset){
                [_projectInfoList removeAllObjects];
            }
            NSDictionary *value = result[@"data"];
            
            NSArray *list= value[@"pageData"];
            for(NSDictionary *dict in list){
                ProjectInfoData *infoData = [[ProjectInfoData alloc] init];
                [infoData setInfo:dict];
                [_projectInfoList addObject:infoData];
            }
            BOOL more = list.count>=pageSize;
            complete(YES,more);
        }
        else {
            complete(NO,NO);
            [AppUtils showErrorAlert: result[@"message"]];
        }
    }];
}

- (void)requestProjectDetail:(NSString *)projectId complete:(void (^)(BOOL success))complete
{
    if([AppUtils isEmpty:projectId]){
        complete(NO);
        return;
    }
    NSString *url = [NSString stringWithFormat:@"/app_project/%@",projectId];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:projectId forKey:@"id"];
   
    [[HttpRequest sharedHttpRequest] get:url params:params complete:^(BOOL success, NSDictionary *result) {
        if (success) {
            NSDictionary *value = result[@"data"];
            _projectDetailInfo = [[ProjectInfoData alloc] init];
            [_projectDetailInfo setInfo:value];
            complete(YES);
        }
        else {
            complete(NO);
            [AppUtils showErrorAlert: result[@"message"]];
        }
    }];
}

- (void)requestTaskList:(TaskType)taskType reset:(BOOL)reset page:(NSInteger)pageNo complete:(void (^)(BOOL success,BOOL hasMore))complete
{
    if([AppUtils isEmpty:LOGIN_USER_ID]){
        complete(NO,NO);
        return;
    }
    NSString *url = @"/app_mytask";
    if(taskType == TaskTypeDone){
        url = @"/app_histask";
    }
    NSInteger pageSize = 10;
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:[AppUtils toStr:pageNo] forKey:@"pageNo"];
    [params setValue:[AppUtils toStr:pageSize] forKey:@"pageSize"];
    [params setValue:LOGIN_USER_ID forKey:@"userId"];
    
    [[HttpRequest sharedHttpRequest] get:url params:params complete:^(BOOL success, NSDictionary *result) {
        if (success) {
            NSMutableArray *resultList = _undoneTaskList;
            if(taskType == TaskTypeDone){
                resultList = _doneTaskList;
            }
            if(reset){
                [resultList removeAllObjects];
            }
            NSDictionary *value = result[@"data"];
            NSArray *list= value[@"pageData"];
            
            for(NSDictionary *dict in list){
                WaterInfoData *infoData = [[WaterInfoData alloc] init];
                [infoData setInfo:dict];
                if(taskType == TaskTypeDone){
                    infoData.taskStatus = TaskStatusTypeFinish;
                }
                [resultList addObject:infoData];
            }
            
            BOOL more = list.count>=pageSize;
            complete(YES,more);
        }
        else {
            complete(NO,NO);
            [AppUtils showErrorAlert: result[@"message"]];
        }
    }];
}

- (void)requestSearchWaterRecodeList:(NSString *)dateTime waterId:(NSString *)waterId page:(NSInteger)pageNo reset:(BOOL)reset complete:(void (^)(BOOL success,BOOL hasMore))complete
{
    NSInteger pageSize = 15;
    NSString *url = @"/app_inspect";
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:dateTime forKey:@"inspecterDt"];
    [params setValue:waterId forKey:@"watId"];
    [params setValue:[AppUtils toStr:pageNo] forKey:@"pageNo"];
    [params setValue:[AppUtils toStr:pageSize] forKey:@"pageSize"];
    
    [[HttpRequest sharedHttpRequest] get:url params:params complete:^(BOOL success, NSDictionary *result) {
        if (success) {
            if(reset){
                [_waterRecordList removeAllObjects];
            }
            NSDictionary *value = result[@"data"];
            NSArray *list= value[@"pageData"];
            
            for(NSDictionary *dict in list){
                WaterRecodeItemData *infoData = [[WaterRecodeItemData alloc] init];
                [infoData setInfo:dict];
                [_waterRecordList addObject:infoData];
            }
            BOOL more = list.count>=pageSize;
            complete(YES,more);
        }
        else {
            complete(NO,NO);
            [AppUtils showErrorAlert: result[@"message"]];
        }
    }];
}

- (void)requestWaterRecodeDetail:(NSString *)recordId complete:(void (^)(BOOL success))complete
{
    if([AppUtils isEmpty:recordId]){
        complete(NO);
        return;
    }
    NSString *url = [NSString stringWithFormat:@"/app_inspect/%@",recordId];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:recordId forKey:@"id"];
    
    [[HttpRequest sharedHttpRequest] get:url params:params complete:^(BOOL success, NSDictionary *result) {
        if (success) {
            NSDictionary *value = result[@"data"];
            _waterRecordDetail = [[WaterRecodeItemData alloc] init];
            [_waterRecordDetail setInfo:value];
            complete(YES);
        }
        else {
            complete(NO);
            [AppUtils showErrorAlert: result[@"message"]];
        }
    }];

}

/**
 * 上传多张图片
 */
- (void)requestUploadImages:(NSArray *)imgs flag:(NSString *)flagStr completion:(void(^)(BOOL success, NSArray *fileArr))completion
{
    if(![AppUtils hasConnected:YES]){
        completion(NO, nil);
        return;
    }
    if ([AppUtils isEmptyArray:imgs]) {
        completion(YES, nil);
        return;
    }
    NSMutableArray *files = [[NSMutableArray alloc] init];
    NSDictionary *item = nil;
    NSData *data = nil;
    for (UIImage *img in imgs) {
        data =  UIImageJPEGRepresentation(img, 1.0);
        item = [NSDictionary dictionaryWithObjectsAndKeys:data, @"file", @"jpeg", @"name", nil];
        [files addObject:item];
    }
    NSString *url = @"/app_file";
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:flagStr forKey:@"fileFlag"];
    [[HttpRequest1 sharedHttpRequest] upload:url params:params files:files complete:^(BOOL success, NSDictionary *result) {
        if (success) {
            NSArray *arr= result[@"data"];
            completion(YES, arr);
        } else {
            [AppUtils showErrorAlert: @"图片上传失败"];
            completion(NO, nil);
        }
    }];
}

- (void)requestAddRecoreOrDeal:(NSString *) taskId type:(BOOL)isAdd text:(NSString *)text fieldIds:(NSArray *)fieldIds completion:(void(^)(BOOL success))complete
{
    if([AppUtils isEmpty:taskId]){
        complete(NO);
        return;
    }
    
    NSString *url = isAdd ? @"/app_inspect/create" : @"/app_inspect_result" ;
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if(isAdd){
        [params setValue:taskId forKey:@"waterId"];
        [params setValue:text forKey:@"supervisePropose"];
        [params setValue:LOGIN_USER_ID forKey:@"userId"];
        InspectResultType resultType = [AppUtils isEmpty:text]||[@"无" isEqualToString:text] ?InspectResultTypeOK :InspectResultTypeBad;
        [params setValue:[AppUtils toStr:resultType] forKey:@"resultStatus"];
    }else{
        [params setValue:taskId forKey:@"id"];
        [params setValue:[AppUtils toStr:ScoutStatusFinish] forKey:@"status"];
        [params setValue:text forKey:@"manageOpinion"];
    }
    [params setValue:fieldIds forKey:@"fileIds"];
    
    [[HttpRequest sharedHttpRequest] get:url params:params complete:^(BOOL success, NSDictionary *result) {
        if (success) {
            complete(YES);
        }
        else {
            complete(NO);
            [AppUtils showErrorAlert: result[@"message"]];
        }
    }];
}

//请求tab页的水体
- (void)requestWaterDirtyList:(NSString *)waterName complete:(void (^)(BOOL success))complete
{
    NSString *url = @"/app_water_dirty";
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:waterName forKey:@"wName"];
    [_waterDirtyList removeAllObjects];
    
    [[HttpRequest sharedHttpRequest] get:url params:params complete:^(BOOL success, NSDictionary *result) {
        if (success) {
            NSArray *value = result[@"data"];
            for(NSDictionary *dict in value){
                WaterDirtyData *data = [[WaterDirtyData alloc] init];
                [data setInfo:dict];
                [_waterDirtyList addObject:data];
            }
            complete(YES);
        }
        else {
            complete(NO);
            [AppUtils showErrorAlert: result[@"message"]];
        }
    }];
}

//请求tab页 我所在位置附近的水体 (矩形搜索)
- (void)requestRectWaterDirtyList:(NSArray *)positions complete:(void (^)(BOOL success))complete
{
    NSString *url = @"/app_rect_marker";
    [_waterMapList removeAllObjects];
    [[HttpRequest sharedHttpRequest] get:url arrayParams:positions complete:^(BOOL success, NSDictionary *result) {
        if (success) {
            NSArray *value = result[@"data"];
//            value = @[@{@"id":@"8af5c3555c4786f9015c4791354c0007",
//                                        @"position":@"121.882508,29.485231;121.881781,29.483455;121.883434,29.483691;121.883299,29.484791",
//                                        @"dirtyName":@"沾水",@"mapTag":@"121.882782,29.484335",
//                                        @"wName":@"上碶门池",@"waterId":@"8af5c3555c4786f9015c4791354c0007",
//                                        @"isDirect":@"Y",@"dirtyPlace":@"螺口店面",
//                                        @"wLocation":@"NBXS0010CT",@"status":@"00",
//                                        @"wTypeName":@"劣V类"},@{@"id":@"c3555c4733f9015c4791354c0007",
//                                                               @"position":@"121.882508,29.485231;121.881781,29.483455;121.883434,29.483691",
//                                                               @"dirtyName":@"沾水",@"mapTag":@"121.874557,29.484603",
//                                                               @"wName":@"应用池",@"waterId":@"8af5555c4786f9015c4791354c0007",
//                                                               @"isDirect":@"Y",@"dirtyPlace":@"螺口店面",
//                                                               @"wLocation":@"NBXS0010CT",@"status":@"00",
//                                                               @"wTypeName":@"劣V类"}];
            for(NSDictionary *dict in value){
                WaterDirtyData *data = [[WaterDirtyData alloc] init];
                [data setInfo:dict];
                [_waterMapList addObject:data];
            }
            complete(YES);
        }
        else {
            complete(NO);
            [AppUtils showErrorAlert: result[@"message"]];
        }
    }];
    
}






@end
